---
title: "Replication file: Challenger issue entrepreneurship, mainstream strategies and public issue salience"
author: "Sophia Hunger"
date: '2022-07-19'
output: 
  html_document:
    toc: false
    code_folding: hide
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, 
                      warning=FALSE, 
                      message=FALSE, 
                      chache=FALSE)

library(magrittr)
library(ggeffects)
library(sjmisc)
library(lme4)
library(splines)
library(ggplot2)
library(sjstats)
library(haven)
library(lmerTest)
library(texreg)
```


```{r load_data}

## load data
immig_full_data <- read_dta("Williams_Hunger_Final_EPSR_Data_final.dta")


```

### Model 1 - 3

```{r model1}
###Model 1
m1 <- glmer(
  immigration_mip_w2_3 ~ sal_immig_RRP + lr_self + age + sex_2 + edu + marital_2 + income + rural + ps_immig_sal_sansRRPw + east + noneu + wave_2 + (1 | id), 
  data = immig_full_data, 
  family = binomial(link = "logit")
)
# summary(m1)
# icc(m1)

###Model 2               
m2 <- glmer(
  immigration_mip_w2_3 ~ sal_immig_RRP + cr_rr_pos_dist + cr_change_immig_pos + lr_self + age + sex_2 + edu + marital_2 + income + rural + east + noneu + ps_immig_sal_sansRRPCRw + wave_2 + (1 | id), 
  data = immig_full_data, 
  family = binomial(link = "logit")
)
# summary(m2)
# icc(m2)


###Model 3               
m3 <- glmer(
  immigration_mip_w2_3 ~ sal_immig_RRP + cl_rr_pos_dist + cl_change_immig_pos + lr_self + age + sex_2 + edu + marital_2 + income + rural + east + noneu + ps_immig_sal_sansRRPCLw + wave_2 + (1 | id), 
  data = immig_full_data, 
  family = binomial(link = "logit")
)
# summary(m3)
# icc(m3)

screenreg(list(m1, m2, m3))


```

### Figure 1

```{r model1_plot}
###Figure 2
m1_plot<-ggpredict(m1, "sal_immig_RRP [0:50]", condition=c(age=47, 
                                                           sex_2=0, 
                                                           edu=2, 
                                                           marital_2=1, 
                                                           income=2, 
                                                           rural=0, 
                                                           east=0, 
                                                           noneu=0, 
                                                           wave_2=0, 
                                                           lr_self=5, 
                                                           ps_immig_sal_sansRRPw=.4269))

m1_plot_2<-plot(m1_plot)+
  geom_rug(data=immig_full_data, aes(x=sal_immig_RRP), sides="b", inherit.aes=F)


m1_plot_2+labs(x="Radical-Right Party Immigration Salience", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=scales::number_format(accuracy=0.01, decimal.mark = "."))

```

### Figure 2 (1-3)

```{r model2_plot}

###Figure 2.1
immig_full_Jan212020_rugsubsetCR <- subset(immig_full_data, cr_rr_pos_dist>=0)

m2_1_plot<-ggpredict(m2, "cr_rr_pos_dist [0:5 by=.01]", 
                     condition=c(sal_immig_RRP=1.706, 
                                 cr_change_immig_pos=.041, 
                                 age=47, sex_2=0, 
                                 edu=2, 
                                 marital_2=1, 
                                 income=2, 
                                 rural=0, 
                                 east=0, 
                                 noneu=0, 
                                 wave_2=0, 
                                 lr_self=5, 
                                 ps_immig_sal_sansRRPCRw=.3690), ci.lvl=.90) %>% 
  plot()

m2_1_plot +
  labs(x="Distance Between Centre-Right and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=seq(0.00, 1.00, .1), breaks=seq(0.00, 1.00, .1), limits=c(.00, 1.00))+
  geom_rug(data=immig_full_Jan212020_rugsubsetCR, aes(x=cr_rr_pos_dist), sides="b", inherit.aes=F)

###Figure 2.2
m2_2_plot<-ggpredict(m2, "cr_rr_pos_dist [0:5 by=.01]", condition=c(sal_immig_RRP=15, 
                                                                    cr_change_immig_pos=.041, 
                                                                    age=47, 
                                                                    sex_2=0, 
                                                                    edu=2, 
                                                                    marital_2=1, 
                                                                    income=2, 
                                                                    rural=0, 
                                                                    east=0, 
                                                                    noneu=0, 
                                                                    wave_2=0, 
                                                                    lr_self=5, 
                                                                    ps_immig_sal_sansRRPCRw=.3690), ci.lvl=.90) %>% 
  plot()


m2_2_plot+labs(x="Distance Between Centre-Right and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=seq(0.00, 1.00, .1), 
                     breaks=seq(0.00, 1.00, .1), 
                     limits=c(.00, 1.00))+
  geom_rug(data=immig_full_Jan212020_rugsubsetCR, 
           aes(x=cr_rr_pos_dist), 
           sides="b", 
           inherit.aes=F)

######################################################################################################
###Figure 2.3
m2_4_plot<-ggpredict(m2, "cr_rr_pos_dist [0:5 by=.01]", 
                     condition=c(sal_immig_RRP=30, 
                                 cr_change_immig_pos=.041, 
                                 age=47, sex_2=0, 
                                 edu=2, 
                                 marital_2=1, 
                                 income=2, 
                                 rural=0, 
                                 east=0, 
                                 noneu=0, 
                                 wave_2=0, 
                                 lr_self=5, 
                                 ps_immig_sal_sansRRPCRw=.3690), ci.lvl=.90) %>% 
  plot()

m2_4_plot+labs(x="Distance Between Centre-Right and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", 
               title=NULL) + 
  scale_y_continuous(labels=seq(0.00, 1.00, .1), 
                     breaks=seq(0.00, 1.00, .1), 
                     limits=c(.00, 1.00))+
  geom_rug(data=immig_full_Jan212020_rugsubsetCR, 
           aes(x=cr_rr_pos_dist), 
           sides="b", 
           inherit.aes=F)

```



### Model 4 & 5

```{r model4}


immig_full_w2w3<-subset(immig_full_data, w2==1|w3==1)
###Model 4              
m4 <- lmer(  
  dis_like ~ cr_rr_pos_dist + cr_change_immig_pos + sal_immig_RRP + lr_self + age + sex_2 + edu + marital_2 + income + rural + east + noneu + ps_immig_sal_sansRRPCRw +wave_2 + (1 | id), 
  data = immig_full_w2w3, 
  REML=TRUE)
#summary(m4)
#icc(m4)

###Model 5              
m5 <- lmer(
  dis_like ~ cl_rr_pos_dist + cl_change_immig_pos + sal_immig_RRP + lr_self+ age + sex_2 + edu + marital_2 + income + rural + east + noneu + ps_immig_sal_sansRRPCLw + wave_2 + (1 | id), 
  data = immig_full_w2w3, 
  REML=TRUE)

#summary(m5)
#icc(m5)

screenreg(list(m4, m5),
          custom.model.names = c("Model 4", "Model 5"))
```

### Figure 3 (1-3)

```{r model3_plot}

############################################################################################
###Figure 4.1
immig_full_Jan212020_rugsubsetCL<-subset(immig_full_data, cl_rr_pos_dist>=0)
m3_1_plot<-ggpredict(m3, "cl_rr_pos_dist [0:5 by=.01]", condition=c(sal_immig_RRP=1.706, 
                                                                    cl_change_immig_pos=.36, 
                                                                    age=47, 
                                                                    sex_2=0, 
                                                                    edu=2, 
                                                                    marital_2=1, 
                                                                    income=2, 
                                                                    rural=0, 
                                                                    east=0, 
                                                                    noneu=0, 
                                                                    wave_2=0, 
                                                                    lr_self=5, 
                                                                    ps_immig_sal_sansRRPCLw=.3815), ci.lvl=.90) %>% 
  plot()

m3_1_plot+labs(x="Distance Between Centre-Left and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=seq(0.00, 1.00, .1), breaks=seq(0.00, 1.00, .1), limits=c(.00, 1.00))+geom_rug(data=immig_full_Jan212020_rugsubsetCL, aes(x=cl_rr_pos_dist), sides="b", inherit.aes=F)

############################################################################################
###Figure 4.2
m3_2_plot<-ggpredict(m3, "cl_rr_pos_dist [0:5 by=.01]", condition=c(sal_immig_RRP=15, 
                                                                    cl_change_immig_pos=.36, 
                                                                    age=47, 
                                                                    sex_2=0, 
                                                                    edu=2, 
                                                                    marital_2=1, 
                                                                    income=2, 
                                                                    rural=0, 
                                                                    east=0, 
                                                                    noneu=0, 
                                                                    wave_2=0, 
                                                                    lr_self=5, 
                                                                    ps_immig_sal_sansRRPCLw=.3815), ci.lvl=.90) %>% 
  plot()

m3_2_plot+labs(x="Distance Between Centre-Left and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=seq(0.00, 1.00, .1), breaks=seq(0.00, 1.00, .1), limits=c(.00, 1.00))+geom_rug(data=immig_full_Jan212020_rugsubsetCL, aes(x=cl_rr_pos_dist), sides="b", inherit.aes=F)

############################################################################################
###Figure 4.3
m3_4_plot<-ggpredict(m3, "cl_rr_pos_dist [0:5 by=.01]", condition=c(sal_immig_RRP=30, 
                                                                    cl_change_immig_pos=.36, 
                                                                    age=47, 
                                                                    sex_2=0, 
                                                                    edu=2, 
                                                                    marital_2=1, 
                                                                    income=2, 
                                                                    rural=0, 
                                                                    east=0, 
                                                                    noneu=0, 
                                                                    wave_2=0, 
                                                                    lr_self=5, 
                                                                    ps_immig_sal_sansRRPCLw=.3815), ci.lvl=.90) %>% 
  plot()

m3_4_plot+labs(x="Distance Between Centre-Left and Radical Right Parties", 
               y="Likelihood of Viewing Immigration as a MIP", title=NULL)+
  scale_y_continuous(labels=seq(0.00, 1.00, .1), breaks=seq(0.00, 1.00, .1), limits=c(.00, 1.00))+geom_rug(data=immig_full_Jan212020_rugsubsetCL, aes(x=cl_rr_pos_dist), sides="b", inherit.aes=F)

```




